package com.csw.emsDeptPink.util;

import org.apache.commons.codec.digest.DigestUtils;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;

public class MD5Utils {
	// 给定一个字符串
	static String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	private static Random rand;

	static {
		try {
			rand = SecureRandom.getInstanceStrong();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
	}

	public static String getSalt() {
		StringBuffer salt = new StringBuffer();
		for (int i = 0; i <= 7; i++) {
			salt.append(str.charAt(rand.nextInt(62)));
		}
		return salt.toString();
	}

	public static String getNum() {
		StringBuffer salt = new StringBuffer();
		for (int i = 0; i <= 8; i++) {
			salt.append(str.charAt(rand.nextInt(10)));
		}
		return salt.toString();
	}

	public static String getPassword(String upassword) {
		return DigestUtils.md5Hex(upassword);
	}
}
